package com.caiden_micheal.org.mapper;

import com.caiden_micheal.org.domain.Org;
import com.caiden_micheal.org.dto.OrgSelectDTO;
import com.caiden_micheal.org.vo.OrgQueryVO;
import com.caiden_micheal.permission.domain.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrgMapper {
    List<Org> findOrgListPaginationQuery(@Param("org") OrgQueryVO org);

    Integer findOrgListQueryCount(@Param("org") OrgQueryVO org);

    @Select("SELECT id,org_name FROM sys_org ORDER BY create_time DESC")
    List<OrgSelectDTO> findOrgSelectDatas();

    @Select("SELECT * FROM sys_org WHERE org_name=#{orgName}")
    Org findByName(@Param("orgName") String orgName);

    @Insert("INSERT INTO sys_org (org_name,parent_org_id,creation_date,create_time,disabled) VALUES(#{org.orgName},#{org.parentOrgId},#{org.creationDate},NOW(),#{org.disabled})")
    void addOrg(@Param("org") Org org);

    @Select("SELECT * FROM sys_org WHERE id=#{id}")
    Org findById(@Param("id") Long id);

    void update(@Param("org") Org org);

    List<Org> findByIdList(@Param("orgIdList") List<Long> orgIdList, @Param("org") OrgQueryVO orgQueryVO);

    Integer findOrgCountByOrgIds(@Param("orgIdList") List<Long> orgIdList, @Param("org") OrgQueryVO orgQueryVO);

    List<Org> findByExcludeOrgIdList(@Param("orgIdList") List<Long> orgIdList, @Param("org") OrgQueryVO orgQueryVO);

    Integer findByExcludeOrgIdListCount(@Param("orgIdList") List<Long> orgList, @Param("org") OrgQueryVO orgQueryVO);

    void addOrgPermissionByOrgIds(@Param("orgList") List<Org> orgList, @Param("permission") Permission permission);

    List<Org> findAllOrgByIdList(@Param("orgIdList") List<Long> orgIds);

    List<OrgSelectDTO> findSelectByExcludeOrgIdList(@Param("orgIdList") List<Long> orgIdList);

    @Select("SELECT * FROM sys_org WHERE parent_org_id=#{parentOrgId}")
    List<Org> findByParentId(@Param("parentOrgId") Long parentOrgId);
}
